package cn.jieruoda.eb.article;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/articles")
public class ArticleController {

    final ArticleRepository articleRepository;

    @GetMapping
    public Page<Article> list(@RequestBody PageRequest pageRequest) {
        return articleRepository.findAll(pageRequest);
    }

    @PostMapping
    public Article post(@RequestBody Article article) {
        return articleRepository.save(article);
    }

}
